package com.youcan.search.helper;


import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;

import wl.zs.utils.DateUtils;
import wl.zs.utils.TypeValueUtil;
 

/**
 * solr查询需要的参数只能是String，本类将常见的简单数据类型转换成<code>String</code>，不支持复杂的对象。
 * 
 */
public class QueryParamBuilder {

	/**
	 * 将map的值转换成 @see java.leng.String
	 * 
	 * @param data
	 * @return
	 */
	public static Map<String, String> getQueryParam(Map<String, Object> data) {
		Map<String, String> params = new HashMap<String, String>();
		for (String key : data.keySet()) {
			params.put(key, TypeValueUtil.getStringValue(data.get(key)));
		}
		return params;
	}
	
	/**
	 * @param str
	 * @return
	 */
	public static String formatIndexDate(String str) {
		Calendar c = Calendar.getInstance();
		c.setTime(DateUtils.toDate(str));
		c.set(Calendar.HOUR_OF_DAY, 0);
		c.set(Calendar.MINUTE, 0);
		c.set(Calendar.SECOND, 0);
		SimpleDateFormat sdf = new SimpleDateFormat(
				"yyyy-MM-dd'T'HH'\\':mm'\\':ss'Z'");
		sdf.setTimeZone(TimeZone.getTimeZone("US"));
		return sdf.format(c.getTime());
	}
}
